package view.mh;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.lang.reflect.Array;
import java.util.ArrayList;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.Border;
import javax.swing.border.LineBorder;

import controller.Controller;
import model.*;



public class WeatherGUI implements ViewInterface {

	JFrame frame = null;
	private String landName = null;
	Controller controller;
	JComboBox land;
	
	
	
	public WeatherGUI(JFrame jframe, Controller controller) {
		this.frame = jframe;
		this.controller = controller;
	}

	public String getSelectedLand() {
		return land.getSelectedItem().toString();
	}

	public void fenster(ArrayList<String> testfall) {

		// JFrame frame = new
		// JFrame("Wetterstation V1.0 (c) 2013 by alfatraining");
		frame.setSize(900, 700);
		frame.setLocation(500, 200);

		JPanel panel = new JPanel();
		panel.setBackground(Color.BLUE);
		panel.setLayout(new BorderLayout());

		/**
		 * 
		 * "�berschrift"
		 */

		JPanel ueberschrift = new JPanel();

		JTextField label = new JTextField(
				"Wetterstation light (c) 2013 by Java Group Enterprises");
		label.setBackground(Color.CYAN);
		label.setSize(100, 100);
		label.setEditable(false);
		ueberschrift.add(label);
		ueberschrift.setBackground(Color.CYAN);
		Border border = new LineBorder(Color.BLACK);
		ueberschrift.setBorder(border);

		panel.add(ueberschrift, BorderLayout.NORTH);
		panel.add(hauptFenster(testfall));
		panel.add(unteresMenue(), BorderLayout.SOUTH);

		frame.add(panel);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setVisible(true);

	}

	public JPanel hauptFenster(ArrayList<String> testfall) {

		JPanel hauptFenster = new JPanel(new BorderLayout());

		JPanel oberesHauptFenster = new JPanel(new BorderLayout());

		/**
		 * Auswahlmen�s
		 */

		JPanel auswahlMenues = new JPanel(new FlowLayout());
		auswahlMenues.setBackground(Color.BLUE);

		//String[] landName = new String[testfall.size()];
		
		//landName = testfall.toArray(new String[testfall.size()]);
		CountryModel[] landName = new CountryModel[]{
									new CountryModel("Amerika"),
									new CountryModel("Deutschland"),
									new CountryModel("Frankreich")};
		
		
		
		// int laenge = testfall.size();
		// for(int i=0; i <= laenge; i++){
		// landName[i] = testfall[i].toString;
		// }

		
		
		land = new JComboBox(landName);
		
		land.setToolTipText("Bitte w�hlen Sie das Land aus.");

		

		final JComboBox airport = new JComboBox();

		airport.setToolTipText("Bitte w�hlen Sie den Flughafen aus.");
		

		auswahlMenues.add(land);
		auswahlMenues.add(airport);
		
		
		
		
		land.addItemListener(controller);
		land.addActionListener(controller);
		land.setActionCommand(controller.action.GET_AIRPORTS.command());
		
		
		oberesHauptFenster.setBackground(Color.BLUE);
		oberesHauptFenster.add(auswahlMenues, BorderLayout.NORTH);
		hauptFenster.setBackground(Color.BLUE);
		hauptFenster.add(oberesHauptFenster, BorderLayout.NORTH);
		return hauptFenster;
	}
	
	

	
	

	public JPanel unteresMenue() {

		JPanel unteresPanel = new JPanel(new FlowLayout());

		JButton aktualisieren = new JButton("Aktualisieren");
		aktualisieren.addActionListener(controller);
		aktualisieren.setActionCommand(controller.action.ACTUALIZE.command());

		aktualisieren.setToolTipText("Aktualisierung der Wetterdaten");
		aktualisieren.setBackground(Color.YELLOW);

		JButton drucken = new JButton("Drucken");
		drucken.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub

			}
		});

		drucken.setBackground(Color.YELLOW);
		drucken.setToolTipText("druckt das aktuelle Wetter aus");

		JButton beenden = new JButton("Beenden");
		beenden.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				System.exit(0);
			}
		});
		beenden.setBackground(Color.RED);
		beenden.setToolTipText("beendet das aktuelle Programm");

		unteresPanel.add(aktualisieren);
		unteresPanel.add(drucken);
		unteresPanel.add(beenden);
		unteresPanel.setBackground(Color.BLUE);
		Border border = new LineBorder(Color.BLACK);
		unteresPanel.setBorder(border);
		return unteresPanel;

	}

	@Override
	public void setController(Controller control) {
		// TODO Auto-generated method stub
		this.controller = control;
		
	}

	@Override
	public void build() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void update(Model model) {
		// TODO Auto-generated method stub
		
	}

	
}
